package emulator.analyzer;

import java.io.PrintStream;

import emulator.assembler.Instruction;
import emulator.hardware.HwWord;

public class AddressDefinition {
	public final static int TYPE_ZP = 0;
	public final static int TYPE_ADR = 1; 
	public final static int TYPE_LOW = 2; 
	public final static int TYPE_HIGH = 3; 
	
	private int type;
	private int full_address;
	private Instruction instruction;
	private int instruction_address;
	
	public void setType(int type) {
		this.type = type;
	}
	public int getType() {
		return type;
	}
	public void setFullAddress(int full_address) {
		this.full_address = full_address;
	}
	public int getFullAddress() {
		return full_address;
	}
	public void setInstruction(Instruction instruction) {
		this.instruction = instruction;
	}
	public Instruction getInstruction() {
		return instruction;
	}
	public void setInstructionAddress(int instruction_address) {
		this.instruction_address = instruction_address;
	}
	public int getInstructionAddress() {
		return instruction_address;
	}
	public void print(PrintStream out, String prefix) {
		out.print(prefix + getTypeName() + "($" + new HwWord(getFullAddress()) + ") ");
		if (getInstruction() != null)
			getInstruction().print(out, " <- ", getInstructionAddress());
	}
	public String print(String prefix) {
		String text = prefix + getTypeName() + "($" + new HwWord(getFullAddress()) + ") ";
		if (getInstruction() != null)
			text += getInstruction().print(" <- ", getInstructionAddress());
		return text;
	}
	public String getTypeName() {
		String result = "???";
		switch(getType())
		{
		case TYPE_ADR:	result = "AD"; break;
		case TYPE_ZP:	result = "ZP"; break;
		case TYPE_LOW:	result = "LO"; break;
		case TYPE_HIGH:	result = "HI"; break;
		}
		return result;
	}
}
